#include <chrono>
#include <rclcpp/rclcpp.hpp>
#include <test_self_contain_interface/msg/test_add.hpp>

using namespace std::chrono_literals;

class AddClient : public rclcpp::Node {
public:
  AddClient() : Node("add_client") {
    publisher_ =
        this->create_publisher<test_self_contain_interface::msg::TestAdd>(
            "test_add", 10);
    timer_ =
        this->create_wall_timer(1s, std::bind(&AddClient::send_request, this));
  }
  void send_request() {
    test_self_contain_interface::msg::TestAdd request;
    request.a = 10;
    request.b = 20;
    publisher_->publish(request);
    RCLCPP_INFO(this->get_logger(), "Published: %d + %d = %d", request.a,
                request.b, request.a + request.b);
  }

private:
  // publisher
  rclcpp::Publisher<test_self_contain_interface::msg::TestAdd>::SharedPtr
      publisher_;
  rclcpp::TimerBase::SharedPtr timer_;
};

int main(int argc, char *argv[]) {
  rclcpp::init(argc, argv);
  rclcpp::spin(std::make_shared<AddClient>());
  rclcpp::shutdown();
  return 0;
}